/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;
import java.util.Comparator;

/**
 * <p>Project: jse2204 - Arr6
 * <p>Powered by webrx On 2022-09-06 14:39:34
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Arr6 {
    public static void main(String[] args) {
        var ls = "java,python,php,html,css,javascript,mysql,c,linux,go".split(",");
        //1
        System.out.println("排序前：" + Arrays.toString(ls));
        Arrays.sort(ls);
        System.out.println("排升序：" + Arrays.toString(ls));
        Arrays.sort(ls, (a, b) -> b.compareTo(a));
        System.out.println("排降序：" + Arrays.toString(ls));
        Arrays.sort(ls, Comparator.reverseOrder());
        System.out.println("排降序：" + Arrays.toString(ls));
        Arrays.sort(ls, (a, b) -> Math.random() > .5 ? 1 : -1);
        System.out.println("排乱序：" + Arrays.toString(ls));

        System.out.println("-------------------");
        //2 打字符串长度排序
        System.out.println("排序前：" + Arrays.toString(ls));
        Arrays.sort(ls, Comparator.comparingInt(String::length));
        System.out.println("排升序：" + Arrays.toString(ls));
        Arrays.sort(ls, (a, b) -> b.compareTo(a));
        Arrays.sort(ls,(a,b)->b.length()-a.length());
        System.out.println("排降序：" + Arrays.toString(ls));
        Arrays.sort(ls,(a,b)->b.length()-a.length());
        System.out.println("排降序：" + Arrays.toString(ls));
        Arrays.sort(ls, (a, b) -> Math.random() > .5 ? 1 : -1);
        System.out.println("排乱序：" + Arrays.toString(ls));

    }
}
